using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;

namespace NAppUpdater
{
    static class Program
    {
        private static Mutex mutex;
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            bool firstInstance;
            string _loc ="NAPPU"+Application.StartupPath;
            _loc = _loc.Replace("\\", " ");
            mutex = new Mutex(false, _loc, out firstInstance);
            if (firstInstance)
            {
                GC.KeepAlive(mutex);

                Process[] processlist = Process.GetProcessesByName("NApp");

                if (processlist.Length == 0 || (new Kontrola()).ShowDialog() == DialogResult.OK)
                {
                    if (args.Length == 2 && args[0] == "-l")
                    {
                        Application.Run(new Form1(args[1]));
                    }
                    else
                    {
                        Console.WriteLine("-l [Lokacija]");
                        Console.WriteLine("npr. NAppUpdater -l \\SERVER\\NAPP\\Ver1.0.0.0\\");
                        Application.Run(new Form1());
                    }
                }
            }
        }
    }
}